<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/base_body_header.jsp" %>
<%@include file="../common/navbar.jsp" %>
<%@include file="../common/page_content_pre.jsp" %>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal" role="form" action="${GLOBAL.basePath}/neighborhood/list" method="post">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">区域</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="district">
                                <option value="" selected = selected>全部</option>
                                <c:forEach items="${fns:getDictList('district')}" var="item">
                                    <option value="${item.name}" <c:if test="${item.name == neighborhood.district}">selected</c:if>>${item.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label" for="s_nbhName">楼盘名</label>

                        <div class="col-sm-2">
                            <input class="form-control" id="s_nbhName" type="text" name="nbhName" placeholder="请输入楼盘名"
                                   value="${neighborhood.nbhName}"/>
                        </div>
                        <div class="col-sm-2">
                            <button class="btn btn-primary btn-sm" onsubmit="return false;">
                                查询
                                <i class="icon-search align-top bigger-125 icon-on-right"></i>
                            </button>
                        </div>
                    </div>

                </fieldset>


            </form>

        </div>
        <shiro:hasPermission name="neighborhood:edit">
            <div class="col-sm-12">
                <button class="btn btn-xs btn-success" id="add_btn">
                    添加
                    <i class="icon-plus align-top bigger-125 icon-on-right"></i>
                </button>
            </div>
        </shiro:hasPermission>
        <div class="col-xs-12">
            <div class="table-responsive">

                <table id="list-table" class="table table-striped table-bordered table-hover" width="100%">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th class="hidden-480">小区名称</th>
                        <th class="hidden-480">区域</th>
                        <th class="hidden-480">已录入栋数</th>
                        <th class="hidden-480">总栋数</th>
                        <th class="hidden-480">总户数</th>
                        <th>
                            <i class="icon-time bigger-110 hidden-480"></i>
                            创建时间
                        </th>
                        <th class="hidden-480">楼栋信息</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>


</div>
<!-- /.page-content -->

<%@include file="../common/page_content_suf.jsp" %>
<%@include file="../common/script.jsp" %>

<script type="text/javascript">
    var neighborhoodListTable;
    jQuery(function ($) {

        $("#add_btn").on("click", function () {
            addClick();
        });

        $('.date-picker').datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        neighborhoodListTable = $('#list-table').dataTable({
            "sAjaxSource": "${GLOBAL.basePath}/neighborhood/asynList",
            "fnServerData": function (sSource, aDataSet, fnCallback) {
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aDataSet,
                    "success": fnCallback,
                    "beforeSend":function (XMLHttpRequest) {
                        layer.load();
                    },
                    "complete":function (XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    }
                });
            },
            "fnServerParams": function (aoData) {//向服务器传额外的参数
                <c:if test="${not empty aoData}">
                aoData.push(${aoData});
                </c:if>
            },
            "bSort": false,
            "bFilter": false,
            "bServerSide": true,
            "bProcessing": false,
            "bLengthChange": false,
            "bSearching": false,
            "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
            "oLanguage": {
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
                "sInfoEmpty": "No data"
            },
            "aoColumns": [
                {
                    "sName": "nbhId", "mDataProp": "nbhId", "sWidth": "60px", "mRender": function (data, type, full) {
                    return  data;
                }
                },
                {"mDataProp": "nbhName"},
                {"mDataProp": "districtName", "sWidth": "230px"},
                {"mDataProp": "buildingInput"},
                {"mDataProp": "buildingTotal"},
                {"mDataProp": "residenters"},
                {"mDataProp": "createDate", "sWidth": "180px"},
                {
                    "mDataProp": "nbhId", "mRender": function (data, type, full) {
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<shiro:hasPermission name='cellinfo:view'><button class='btn btn-xs btn-primary' pkId='" + data + "' onclick='viewClick(this)'>"
                                + "查看详情"
                                + "</button></shiro:hasPermission>"
                                + "</div>";
                    }
                },
                {
                    "mDataProp": "nbhId", "sWidth": "120px", "mRender": function (data, type, full) {
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<shiro:hasPermission name='neighborhood:edit'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='editClick(this)'>"
                                + "<i class='icon-edit bigger-120'></i>"
                                + "</button></shiro:hasPermission>"
                                + "<shiro:hasPermission name='neighborhood:delete'><button class='football-del btn btn-xs btn-danger' pkId='" + data + "' onclick='delClick(this)'>"
                                + "<i class='icon-trash bigger-120'></i>"
                                + "</button></shiro:hasPermission>"
                                + "<shiro:hasPermission name='neighborhood:detail'><button class='football-del btn btn-xs btn-success' pkId='" + data + "' onclick='detailClick(this)'>"
                                + "<i class='icon-list-ul bigger-120'></i>"
                                + "</button></shiro:hasPermission>"
                                + "</div>";
                }
                }
            ]
        });

    });


    var addClick = function () {
        document.location.href = "${GLOBAL.basePath}/neighborhood/add";
    };

    var editClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/neighborhood/edit?nbhId=" + $(obj).attr("pkId");
    };

    var detailClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/neighborhood/detail?nbhId=" + $(obj).attr("pkId");
    };

    var viewClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/cellInfo/list?nbhId=" + $(obj).attr("pkId");
    };

    var delClick = function (obj) {
        layer.confirm("确定要删除小区信息吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/neighborhood/delete", "POST", {nbhId: $(obj).attr("pkId")});
            layer.alert("删除成功", {icon: 1, title: '提示', btn: ['OK']});
            neighborhoodListTable.fnDraw();
        })
    }

</script>
